package com.baitiaojun.api.domain.user;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import javax.validation.constraints.Pattern;
import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ApiModel("用户个人信息")
@Document(indexName = "user_info")
public class UserInfo {

    @Id
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(readOnly = true)
    private Long id;

    @JsonSerialize(using = ToStringSerializer.class)
    @Field(type = FieldType.Long)
    @ApiModelProperty(readOnly = true)
    private Long userid;

    @Field(type = FieldType.Text)
    @Pattern(regexp = "[\\u4e00-\\u9fa5|0-9|A-Z|a-z_]{0,16}", message = "昵称只能是英文、汉字、数字组成，且长度在16个字符以内")
    @ApiModelProperty("用户昵称")
    private String nick;

    @Field(type = FieldType.Keyword, index = false)
    @ApiModelProperty("用户头像")
    private String avatar;

    @Field(type = FieldType.Keyword, index = false)
    @Pattern(regexp = "^[01]$", message = "性别只能是0或者1，1代表是女，0代表男")
    @ApiModelProperty(value = "用户性别", example = "1(女)，0(男)")
    private String gender;

    @Field(type = FieldType.Keyword, index = false)
    @Pattern(regexp = "^\\d{4}\\-(0?[1-9]|1[012])\\-(0?[1-9]|[12][0-9]|3[01])$", message = "日期格式必须是yyyy-mm-dd")
    @ApiModelProperty(value = "用户出生日期", example = "yyyy-mm-dd")
    private String birth;

    @Field(type = FieldType.Date, index = false)
    @ApiModelProperty(readOnly = true)
    private Date createtime;

    @Field(type = FieldType.Date, index = false)
    @ApiModelProperty(readOnly = true)
    private Date updatetime;

    @Field(type = FieldType.Keyword, index = false)
    @Pattern(regexp = ".{0,24}", message = "签名的长度只能在24个字符以内")
    @ApiModelProperty("用户签名")
    private String sign;

    @Field(type = FieldType.Boolean, index = false)
    @ApiModelProperty(hidden = true)
    private Boolean followed = false;

    @ApiModelProperty(hidden = true)
    @Field(type = FieldType.Boolean, index = false)
    private Boolean following = false;

    @Field(type = FieldType.Integer, index = false)
    @ApiModelProperty(hidden = true)
    private Integer coinCount;

    @Field(type = FieldType.Integer, index = false)
    @ApiModelProperty(hidden = true)
    private Integer fansCount;

    @Field(type = FieldType.Integer, index = false)
    @ApiModelProperty(hidden = true)
    private Integer followingCount;

    @Field(type = FieldType.Integer, index = false)
    @ApiModelProperty(hidden = true)
    private Integer momentsCount;
}